
//广告图控制器
food.controller('BannerController',function($scope,$http){

    //请求广告图数据
    $http({
        method:'GET',
        url:"../Api/home.php?action=banner"
    }).then(function(result){
        $scope.banner_list = result.data;
        console.log($scope.banner_list);
    });

});

//首页控制器
food.controller('HomeController',function($scope,$http,$sce){
    //请求新品推荐
    $http({
        method:"GET",
        url:"../Api/home.php?action=news_food"
    }).then(function(result){
        $scope.news_food = result.data;
    });

    //公司简介
    $http({
        method:'GET',
        url:'../Api/home.php?action=about_us'
    }).then(function(result){
        $scope.about = result.data;
        $scope.about.art_content = $sce.trustAsHtml($scope.about.art_content);
    });

    //新闻资讯
    $http({
        method:'GET',
        url:'../Api/home.php?action=home_news'
    }).then(function(result){
        $scope.home_news = result.data;
    });

    //新闻资讯
    $http({
        method:'GET',
        url:'../Api/home.php?action=home_news_one'
    }).then(function(result){
        $scope.home_news_one = result.data;
    });
});


//品牌故事
food.controller('ArticleDetailController',function($scope,$http,$stateParams,$sce){

    $http({
        method:"GET",
        url:"../Api/home.php?action=article_detail&art_id="+$stateParams.art_id
    }).then(function(result){
        $scope.article_detail = result.data;

        //对文章的内容进行处理，在前台可以输出html标签
        $scope.article_detail.art_content = $sce.trustAsHtml($scope.article_detail.art_content);

    });
});


//美食系列
food.controller('FoodListController',function($scope,$http,page,$location){


    //获取食品分类
    $http({
        method:"get",
        url:"../Api/home.php?action=food_cate"
    }).then(function(result){
        $scope.cate_list = result.data;
    });


    //获取总数
    $http({
        method:"get",
        url:"../Api/home.php?action=food_count"
    }).then(function(result){
        $scope.totalItems = result.data.c;
    });

    //设置数据结构
    $scope.currentPage = 1; //当前页码
    $scope.bigTotalItems = 8; //每页显示多少条
    $scope.maxSize = 5;  //中间的页码数

    //判断 $location 所获取的地址 是不是等于 == /food_list
    $scope.food_active = $location.path() == "/food_list" ? true : false;

    //每次页面拿数据所请求的地址
    var url = '../Api/home.php?action=food_list';

    //调用自定义分页服务里面的方法
    page.getData(url,$scope.currentPage,$scope.bigTotalItems).then(function(result){
        $scope.food_list = result;
    });


    $scope.pageChanged = function()
    {
        page.getData(url,$scope.currentPage,$scope.bigTotalItems).then(function(result){
            $scope.food_list = result;
        });
    }


});

//美食系列 按食品分类
food.controller('FoodCateController',function($scope,$http,page,$stateParams){


    //获取食品分类
    $http({
        method:"get",
        url:"../Api/home.php?action=food_cate"
    }).then(function(result){
        $scope.cate_list = result.data;
    });


    //获取总数
    $http({
        method:"get",
        url:"../Api/home.php?action=food_count&fcate_id="+$stateParams.fcate_id
    }).then(function(result){
        $scope.totalItems = result.data.c;
    });

    //设置数据结构
    $scope.currentPage = 1; //当前页码
    $scope.bigTotalItems = 8; //每页显示多少条
    $scope.maxSize = 5;  //中间的页码数
    $scope.fcate_id = $stateParams.fcate_id; //点击的分类id

    //每次页面拿数据所请求的地址
    var url = '../Api/home.php?action=food_list&fcate_id='+$stateParams.fcate_id;

    //调用自定义分页服务里面的方法
    page.getData(url,$scope.currentPage,$scope.bigTotalItems).then(function(result){
        $scope.food_list = result;
    });


    $scope.pageChanged = function()
    {
        page.getData(url,$scope.currentPage,$scope.bigTotalItems).then(function(result){
            $scope.food_list = result;
        });
    }


});

//美食系列 按食品名称
food.controller('FoodNameController',function($scope,$http,page,$stateParams){


    //获取食品分类
    $http({
        method:"get",
        url:"../Api/home.php?action=food_cate"
    }).then(function(result){
        $scope.cate_list = result.data;
    });


    //获取总数
    $http({
        method:"get",
        url:"../Api/home.php?action=food_count&food_name="+$stateParams.food_name
    }).then(function(result){
        $scope.totalItems = result.data.c;
    });

    //设置数据结构
    $scope.currentPage = 1; //当前页码
    $scope.bigTotalItems = 8; //每页显示多少条
    $scope.maxSize = 5;  //中间的页码数
    $scope.food_active = true;
    $scope.food_name = $stateParams.food_name;

    //每次页面拿数据所请求的地址
    var url = '../Api/home.php?action=food_list&food_name='+$stateParams.food_name;

    //调用自定义分页服务里面的方法
    page.getData(url,$scope.currentPage,$scope.bigTotalItems).then(function(result){
        $scope.food_list = result;
    });


    $scope.pageChanged = function()
    {
        page.getData(url,$scope.currentPage,$scope.bigTotalItems).then(function(result){
            $scope.food_list = result;
        });
    }


});


//食品详细页面
food.controller("FoodDetailController",function($scope,$http,$stateParams,$sce){

    //食品详细界面
    $http({
        url:"../Api/home.php?action=food_detail&food_id="+$stateParams.food_id,
        method:"get"
    }).then(function(result){
        $scope.food_detail = result.data;
        $scope.food_detail.food_content = $sce.trustAsHtml($scope.food_detail.food_content);
    });
});


//店面列表
food.controller('ShopListController',function($scope,$http,page,$location){


    //获取地区分类
    $http({
        method:"get",
        url:"../Api/home.php?action=region_list"
    }).then(function(result){
        $scope.region_list = result.data;
    });


    //获取总数
    $http({
        method:"get",
        url:"../Api/home.php?action=shop_count"
    }).then(function(result){
        $scope.totalItems = result.data.c;
    });

    //设置数据结构
    $scope.currentPage = 1; //当前页码
    $scope.bigTotalItems = 8; //每页显示多少条
    $scope.maxSize = 5;  //中间的页码数

    //判断 $location 所获取的地址 是不是等于 == /food_list
    $scope.shop_active = $location.path() == "/shop_list" ? true : false;

    //每次页面拿数据所请求的地址
    var url = '../Api/home.php?action=shop_list';

    //调用自定义分页服务里面的方法
    page.getData(url,$scope.currentPage,$scope.bigTotalItems).then(function(result){
        $scope.shop_list = result;
    });


    $scope.pageChanged = function()
    {
        page.getData(url,$scope.currentPage,$scope.bigTotalItems).then(function(result){
            $scope.shop_list = result;
        });
    }


});

//店面列表 按地区分类
food.controller('ShopRegionController',function($scope,$http,page,$stateParams){


    //获取地区分类
    $http({
        method:"get",
        url:"../Api/home.php?action=region_list"
    }).then(function(result){
        $scope.region_list = result.data;
    });


    //获取总数
    $http({
        method:"get",
        url:"../Api/home.php?action=shop_count&region_id="+$stateParams.region_id
    }).then(function(result){
        $scope.totalItems = result.data.c;
    });

    //设置数据结构
    $scope.currentPage = 1; //当前页码
    $scope.bigTotalItems = 8; //每页显示多少条
    $scope.maxSize = 5;  //中间的页码数
    $scope.region_id = $stateParams.region_id; //点击的分类id

    //每次页面拿数据所请求的地址
    var url = '../Api/home.php?action=shop_list&region_id='+$stateParams.region_id;

    //调用自定义分页服务里面的方法
    page.getData(url,$scope.currentPage,$scope.bigTotalItems).then(function(result){
        $scope.shop_list = result;
    });


    $scope.pageChanged = function()
    {
        page.getData(url,$scope.currentPage,$scope.bigTotalItems).then(function(result){
            $scope.shop_list = result;
        });
    }


});

//店面列表 按店面名称
food.controller('ShopNameController',function($scope,$http,page,$stateParams){


    //获取地区分类
    $http({
        method:"get",
        url:"../Api/home.php?action=region_list"
    }).then(function(result){
        $scope.region_list = result.data;
    });


    //获取总数
    $http({
        method:"get",
        url:"../Api/home.php?action=shop_count&shop_name="+$stateParams.shop_name
    }).then(function(result){
        $scope.totalItems = result.data.c;
    });

    //设置数据结构
    $scope.currentPage = 1; //当前页码
    $scope.bigTotalItems = 8; //每页显示多少条
    $scope.maxSize = 5;  //中间的页码数
    $scope.shop_active = true;
    $scope.shop_name = $stateParams.shop_name;

    //每次页面拿数据所请求的地址
    var url = '../Api/home.php?action=shop_list&shop_name='+$stateParams.shop_name;

    //调用自定义分页服务里面的方法
    page.getData(url,$scope.currentPage,$scope.bigTotalItems).then(function(result){
        $scope.shop_list = result;
    });


    $scope.pageChanged = function()
    {
        page.getData(url,$scope.currentPage,$scope.bigTotalItems).then(function(result){
            $scope.shop_list = result;
        });
    }


});


//商店详细页面
food.controller("ShopDetailController",function($scope,$http,$stateParams,$sce){

    //食品详细界面
    $http({
        url:"../Api/home.php?action=shop_detail&shop_id="+$stateParams.shop_id,
        method:"get"
    }).then(function(result){
        $scope.shop_detail = result.data;
        //$scope.food_detail.food_content = $sce.trustAsHtml($scope.food_detail.food_content);
    });

});

food.controller('NewListController',function($scope,$http,page,$stateParams){


    $http({

        method:'get',
        url:'../Api/home.php?action=new_list&artcate_id='+$stateParams.artcate_id
    }).then(function(res){
          
          $scope.new_list=res.data;

          
    })
  
  // 
  $http({
       
       method:'get',
       url:'../Api/home.php?action=new_count&artcate_id='+$stateParams.artcate_id
  }).then(function(res){
      $scope.totalItems = res.data.c;
  });

// 组装分页



    //设置数据结构
    $scope.currentPage = 1; //当前页码
    $scope.bigTotalItems = 8; //每页显示多少条
    $scope.maxSize = 5;  //中间的页码数
    
    //每次页面拿数据所请求的地址
    var url = '../Api/home.php?action=new_list&artcate_id='+$stateParams.artcate_id;

    //调用自定义分页服务里面的方法
    page.getData(url,$scope.currentPage,$scope.bigTotalItems).then(function(res){
        $scope.new_list = res;
    });


    $scope.pageChanged = function(){
        page.getData(url,$scope.currentPage,$scope.bigTotalItems).then(function(res){
            $scope.new_list = res;
        });
    }

});

// 新闻资讯详细页

food.controller('NewDetailController',function($scope,$stateParams,$sce,$http){

     $http({

        method:'get',
        url:'../Api/home.php?action=new_detail&art_id='+$stateParams.art_id
     }).then(function(res){

        $scope.new_detail=res.data;
     });


})




//关于我们
food.controller('CompanyController',function($scope,$http,page){
     

     // 数据显示
     $http({
       
        url:'../Api/home.php?action=company_list',
        method:'get'

     }).then(function(res){
        
         $scope.company_list=res.data;


     });

     //分页总数

    $http({
        url:'../Api/home.php?action=ompany_count',
        method:'get'
    }).then(function(res){

        $scope.totalItems=res.data.c;

        
    });

    // 组装分页
    
    //设置数据结构
    $scope.currentPage = 1; //当前页码
    $scope.bigTotalItems = 4; //每页显示多少条
    $scope.maxSize = 5;  //中间的页码数
    
    //每次页面拿数据所请求的地址
    var url = '../Api/home.php?action=company_list';

    //调用自定义分页服务里面的方法
    page.getData(url,$scope.currentPage,$scope.bigTotalItems).then(function(res){
        $scope.company_list = res;
    });


    $scope.pageChanged = function(){
        page.getData(url,$scope.currentPage,$scope.bigTotalItems).then(function(res){
            $scope.company_list = res;
        });
    }






});

// 友情链接控制器

food.controller('FooterController',function($scope,$http){

    
   
   $http({
    method:'get',
    url:'../Api/home.php?action=footer'
   }).then(function(res){

     $scope.footer_list=res.data;

   })



})